package cn.zjq.three;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class EmpMgSys {
    public static boolean updEmployeeById(Employee employee) {
        int index1 = -1;
        for (int i = 0; i < employeeList.size(); i++) {
            Employee stu = employeeList.get(i);
            if (stu.getJobNum()==employee.getJobNum()) {
                index1 = i;
                break;
            }
        }
        if (index1 != -1) {
            employeeList.set(index1, employee);
            return true;
        } else {
            return false;
        }
    }
    public static  List<Employee> employeeList = new ArrayList<>();
    public static void main(String[] args) {

            Employee emp1 = new Employee(1, "张三", 18, 3000);
            Employee emp2 = new Employee(2, "李四", 25, 3500);
            Employee emp3 = new Employee(3, "王五", 22, 3200);
            employeeList.add(emp1);
            employeeList.add(emp2);
            employeeList.add(emp3);

        Scanner input = new Scanner(System.in);
        boolean flag = true;
        do {
            System.out.println("************欢迎来到北大青鸟员工管理系统************");
            System.out.println("请选择您的操作：");
            System.out.println("1.增加员工信息");
            System.out.println("2.删除员工信息");
            System.out.println("3.修改员工信息");
            System.out.println("4.显示全部员工");
            System.out.println("0.退出");
            int x = input.nextInt();
            switch (x) {
                case 1:
                    Employee emp4 = new Employee();
                    System.out.println("请输入新增员工工号：");
                    emp4.setJobNum(input.nextInt());
                    System.out.println("请输入新增员工姓名：");
                    emp4.setName(input.next());
                    System.out.println("请输入新增员工年龄：");
                    emp4.setAge(input.nextInt());
                    System.out.println("请输入新增员工月薪：");
                    emp4.setSalary(input.nextInt());
                    employeeList.add(0,emp4);
                    break;
                case 2:
                    System.out.println("请输入将要删除工号姓名：");
                    String name = input.next();
                    int index=-1;
                    for (int i = 0; i < employeeList.size(); i++) {
                        Employee employee = employeeList.get(i);
                        if (name.equals(employee.getName())) {
                            index = i;
                            break;
                        }
                    }
                    if (index != -1) {
                        employeeList.remove(index);
                        System.out.println("员工信息删除成功。");
                    } else {
                        System.out.println("员工信息删除失败。");
                    }
                    break;
                case 3:
                    Employee stu2 = new Employee();
                    System.out.println("请输入将要修改信息的员工工号：");
                    stu2.setJobNum(input.nextInt());
                    System.out.println("请输入更改后的姓名：");
                    stu2.setName(input.next());
                    System.out.println("请输入更改后的年龄：");
                    stu2.setAge(input.nextInt());
                    System.out.println("请输入更改后的薪水：");
                    stu2.setSalary(input.nextInt());
                    boolean l1 = updEmployeeById(stu2);
                    if (l1) {
                        System.out.println("学生信息修改成功！");
                    } else {
                        System.out.println("学生信息修改失败！");
                    }
                    break;
                case 4:
                    System.out.println("工号\t"+"姓名\t"+"年龄\t"+"薪水\t");
//                    for(int i=0;i<employeeList.size();i++){
//                        Employee emp = (Employee)employeeList.get(i);
//                        System.out.println("-------------------------------");
//                        System.out.println(emp.getJobNum()+"\t\t"+emp.getName()+"\t"+emp.getAge()+"\t\t"+emp.getSalary());
//                    }
                    Iterator<Employee> itor = employeeList.iterator();
                    System.out.println("工号\t"+"姓名\t"+"年龄\t"+"薪水\t");
                    while(itor.hasNext()){
                        Employee emp =(Employee) itor.next();
                        System.out.println("-------------------------------");
                        emp.work();
                        System.out.println(emp.getJobNum()+"\t\t"+emp.getName()+"\t"+emp.getAge()+"\t\t"+emp.getSalary());
                    }
                    break;

                case 0:
                    System.out.println("谢谢使用本程序，欢迎下次光临。。。");
                    flag = false;
                    break;
            }
        }
        while(flag);
    }
}
